package com.sanrenzu.chunbo.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.sanrenzu.chunbo.R;
import com.sanrenzu.chunbo.bean.zxb.GuanggaoLunboBean;
import com.sanrenzu.chunbo.ui.vertical.fenlei.FenLeiActivity;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by My on 2016/8/30.
 */
public class LunBoAdapter extends PagerAdapter {

    private List<GuanggaoLunboBean> list = new ArrayList<>();
    private Context context;
    private LayoutInflater inflater;
    public String id = "";
    public LunBoAdapter(Context context, List<GuanggaoLunboBean> list){
        this.context=context;
        this.list =list;
        inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view==object;
    }

    @Override
    public Object instantiateItem(final ViewGroup container, int position) {
        View view = inflater.inflate(R.layout.adapter_lunbo,container,false);

        ImageView  lunbo_image_adapter_fragment = (ImageView) view.findViewById(R.id.lunbo_image_adapter_fragment);
        id=list.get(position).getRefId()+"";

        Glide.with(context).load(list.get(position).getImageUrl()+"").into(lunbo_image_adapter_fragment);
        lunbo_image_adapter_fragment.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(context, FenLeiActivity.class);
                intent.putExtra("id",id);
                context.startActivity(intent);
            }
        });
        container.addView(view);
        return view;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View)object);
    }
}
